package com.buttlever;

import com.beans.SourceDataSingle;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

/**
 * @author acoffee
 * @create 2021-09-01 17:53
 */
public class ConnectWindowService {

    //给确定按钮，添加点击事件
    public void btnOkAction(ConnectWindowView connectWindowView, Button btnOk, TextField sourceIP,
                            TextField sourcePort, TextField targetIP, TextField targetPort) {
        btnOk.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                connectWindowView.close();//关闭设置界面


                //绑定网络信息
                SourceDataSingle singleData = SourceDataSingle.getInstance();
                singleData.setSourceIP(sourceIP.getText().trim()); //首尾去空格
                singleData.setSourcePort(sourcePort.getText().trim());
                singleData.setTargetIP(targetIP.getText().trim());
                singleData.setTargetPort(targetPort.getText().trim());

                //开启界面
                ButtleGoBangView buttleGoBangView = new ButtleGoBangView();
                buttleGoBangView.show();
            }
        });

    }

    //为取消按钮添加单击事件（点击取消直接退出）
    public void btnCancelAction(Button btnCancel) {
        btnCancel.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                System.exit(0);
            }
        });
    }
}
